package com.ruoyi.labdanger.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.labdanger.domain.LabApplyOccupation;
import com.ruoyi.labdanger.service.ILabApplyOccupationService;

/**
 * 申请领用Controller
 * 
 * @author ruoyi
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/labdanger/occupation")
public class LabApplyOccupationController extends BaseController {
	@Autowired
	private ILabApplyOccupationService labApplyOccupationService;

	/**
	 * 查询申请领用列表
	 */
	@PreAuthorize("@ss.hasPermi('labdanger:occupation:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabApplyOccupation labApplyOccupation) {
		startPage();
		labApplyOccupation.setCreateBy(SecurityUtils.getUsername());
		List<LabApplyOccupation> list = labApplyOccupationService.selectLabApplyOccupationList(labApplyOccupation);
		return getDataTable(list);
	}

	/**
	 * 导出申请领用列表
	 */
	// @PreAuthorize("@ss.hasPermi('labdanger:occupation:export')")
	/*
	 * @Log(title = "申请领用", businessType = BusinessType.EXPORT)
	 * 
	 * @GetMapping("/export") public AjaxResult export(LabApplyOccupation
	 * labApplyOccupation) { List<LabApplyOccupation> list =
	 * labApplyOccupationService.selectLabApplyOccupationList(labApplyOccupation
	 * ); ExcelUtil<LabApplyOccupation> util = new
	 * ExcelUtil<LabApplyOccupation>(LabApplyOccupation.class); return
	 * util.exportExcel(list, "occupation"); }
	 */

	/**
	 * 获取申请领用详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labdanger:occupation:query')")
	@GetMapping(value = "/{applyOccupationId}")
	public AjaxResult getInfo(@PathVariable("applyOccupationId") Long applyOccupationId) {
		return AjaxResult.success(labApplyOccupationService.selectLabApplyOccupationById(applyOccupationId));
	}

	/**
	 * 新增申请领用
	 */
	@PreAuthorize("@ss.hasPermi('labdanger:occupation:edit')")
	@Log(title = "申请领用", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabApplyOccupation labApplyOccupation) {
		labApplyOccupationService.insertLabApplyOccupation(labApplyOccupation);
		return AjaxResult.success(labApplyOccupation);
	}

	/**
	 * 新增申请采购
	 */
	@PreAuthorize("@ss.hasPermi('labdanger:occupation:edit')")
	@Log(title = "申请采购提交流程", businessType = BusinessType.INSERT)
	@PostMapping("/submit")
	public AjaxResult submit(@RequestBody LabApplyOccupation labApplyOccupation) {
		labApplyOccupationService.submitLabApplyOccupation(labApplyOccupation);
		return AjaxResult.success(labApplyOccupation.getInstanceId());
	}

	/**
	 * 修改申请领用
	 */
	@PreAuthorize("@ss.hasPermi('labdanger:occupation:edit')")
	@Log(title = "申请领用", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabApplyOccupation labApplyOccupation) {
		return toAjax(labApplyOccupationService.updateLabApplyOccupation(labApplyOccupation));
	}

	/**
	 * 删除申请领用
	 */
	@PreAuthorize("@ss.hasPermi('labdanger:occupation:edit')")
	@Log(title = "申请领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instanceIds}")
	public AjaxResult remove(@PathVariable Long[] instanceIds) {
		return toAjax(labApplyOccupationService.deleteLabApplyInstanceIds(instanceIds));
	}
}
